home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / AOCE Sample Code / Digital Signatures / Digital Signature Demo / Using Digital Signature Demo / Using Digital Signature Demo
Encoding:
Text File  |  1994-06-23  |  58.3 KB  |  73 lines  |  [ONLN/HLX2]

  1. Digital Signature Demo
  2. Martin Minow
  3. Developer Technical Support
  4. Introduction
  5. The Digital Signature Demo illustrates how AOCE Digital Signature technology may be incorporated into an existing application with a minimum of fuss, and without significantly perturbation of the existing application.
  6. The demo extends the Think Class Library “Tiny Edit” sample program, allowing documents created by TinyEdit to be “signed” and “verified” by the Digital Signature Manager. It also shows how Digital Signatures may be applied to application data, such as the state of checkboxes and radio buttons.
  7. Although the class is defined for, and operates within the Think Class Library organizational structure, it should be relatively easy to adapt it to other class hierarchies. Even if you do not use a class library design in your own applications, you should still be able to use the demo as a basis for your own Digital Signature subroutine library.
  8. Class Hierarchy
  9. The demo defines a CSignature class and two subclasses that are used to manipulate digital signatures. It also adds a few simple classes that add the necessary capabilities to TinyEdit. The class hierarchy is as follows:
  10. Class        Description    
  11. CSignature        The base class for Digital Signatures. CSignature is a subclass to the base-class, CObject. Applications normally do not create instances of this class, but rather use subclasses.    
  12.     CSignedDataFile    This class allows signing or verifying an entire file. It is used to sign a document after it has been saved to disk, and to verify an existing signed document.    
  13.     CSignedObject    This class allows signing or verifying a data object. Your application should create a subclass with the necessary content and methods. You can then use CSignedObject methods to sign or verify the object’s actual data.    
  14. Sample Program
  15. The sample program is an extension of the Think Class Library “TinyEdit” sample application. It extends the CEditDoc class to provide for signed and verified text files and adds a sample class to show how you can sign and verify the contents of a dialog. The demo requires the following source files and their headers:
  16. File    Description
  17. DigitalSignatureDemo.c    This is the main program. It creates a DemoApp class.
  18. DemoApp.c    This is a subclass to CEditApp that lets you open signed documents and starts the signed object demo. It also overrides a “shutdown” method to ensure that the signature context has been removed when your application exits.
  19. DemoEditDoc.c    This is a subclass to CEditDoc that lets you sign and verify documents. It also has methods override CEditDoc methods in order to provide better error messages.
  20. DemoSignedObject.c    This object can sign and verify its data contents. It is a subclass to CSignedObject.
  21. DemoSignedObjectDialog.c    This dialog manages a DemoSignedObject instance. It displays a dialog that lets you change checkbox and text items, and controls signing, verifying, and other CSignedObject functions. It is a subclass to CDLOGDirector. Although it appears to the user as a modal dialog, it is actually implemented as a normal window.
  22. ErrorMessage.c    This file contains two simple display functions for debugging convenience. Error messages were included within the program text so there was a single reference point that explains errors. A production program should preferably store its error messages in resource files
  23. SIGStatusManager.c    This contains the status window manager, window, and window contents. This window is displayed when you specify the built-in status window for a Sign or Verify operation.
  24. SystemSupportsAOCE.c    This subroutine tests for the presence of the AOCE toolbox. It returns an error if the toolbox was not installed or was disabled.
  25. Potential Problems
  26. There are a few things that application developers need to be aware of when using Digital Signatures (these are independent of the example):
  27. •    When your application exits, be sure that you have disposed of the signing context (SIGContextPtr datum). In general, this means that your application should patch the ExitToShell trap with a small subroutine that checks for an active context. The sample program stores the context pointer in a global variable, and overrides CApplication::RemovePatches to check that it has been deleted when the application exits.
  28. •    Signing and verifying take a fairly long time; your application should use a status procedure to entertain the user while signing. This entails a bit of effort: you should not initiate signing or verifying from a Modal Dialog, but should use some form of “standard” window or a non-modal dialog. In the example, the signed object demo uses a subclass of TCL’s CDialog class, which implements a modal-dialog lookalike using the normal window-based event loop. The reason for this is that your status callback should call your normal event loop: if you have an active modal dialog, it will not receive update events properly.
  29. •    When a file is signed, it is set “locked,” i.e., read-only This means that your application must open it read-only (fsRdPerm). Also, your users cannot create a new file with the same name without first, manually, renaming the file or placing it into the trash.
  30. •    The method descriptions only describe the errors that your application needs to handle (because they’re benign or expected). However, note that there are a number of other Digital Signature Manager errors that may also occur. You should carefully test your application to make sure it displays informative error messages in all circumstances.
  31.     There are a number of instances where errors should be detected in your application. For example, signed files are read-only (“locked”) and must be opened with permission set to fsRdPerm, rather than the standard fsRdWrPerm. You should search the demo for Message() calls to see those errors I found worth detecting. 
  32. The remainder of this document describes the individual classes.
  33. CSignature
  34. Introduction
  35. CSignature is the base class for Digital Signature processing. It contains methods that all Digital Signature processing requires, as well as a few utility classes. Your application does not use CSignature directly, but rather uses one of its sub-classes.
  36. Heritage
  37. Superclass    CObject
  38. Subclasses    CSignedDataFile, CSignedObject
  39. Global Variables
  40. Variable    Type    Description
  41. gSIGStatusProc    SIGStatusProcPtr    Default status procedure: pass this to Sign, SignFile, etc. to use the built-in procedure.
  42. gSIGContextPtr    SIGContextPtr    The Signer Manager context. Be sure that your application disposes of any context before it terminates.
  43. Global Functions
  44. void                DisposeSignerContext(void);
  45. Dispose of the signer context, if it exists. This must be called when your application exits (you should trap ExitToShell so you call DisposeSignerContext even if your application crashes).
  46. Instance Variables
  47. Variable    Type    Description
  48. itsContextType    unsigned long    This is the type of the context variable: it is needed only by methods that enable/disable the ShowSigner option as that option is valid only after verifying an object or file.
  49. itsStatusManager    SIGStatusManager    An instance of this class is created if you specify the default status window.
  50. Methods
  51. Construction and destruction methods
  52. void                ISignature(void);
  53. Initialize the private variables.
  54. void                Dispose(void);
  55. Delete any context and signature and dispose of the CSignature object.
  56. Signer Context Methods
  57. void            NewContext(
  58.     unsigned long        contextType
  59. );
  60. Create a new context of the indicated type. The contextType parameter may be one of the following values, which are defined in <DigitalSignature.h>
  61. kSIGSign    Signing a file or object
  62. kSIGVerify    Verifying a file or object
  63. kSIGDigest    Preparing a digest of an object
  64. void                CheckForContext(void);
  65. Fail if there is no current context with a kSIGContextPrepareErr. This would indicate a programming error where one of the routines that requires a context was called when there was no context. For example, calling Sign when your application hasn’t called SignPrepare, would cause this failure.
  66. unsigned long        GetContextType(void);
  67. Return zero if there is no current context, else the type that was specified when the application called NewSignerContext.
  68. Signature Methods
  69. Size                SignPrepare(
  70.     const FSSpec        *signerFile,
  71.     ConstStr255Param    *prompt
  72. );
  73. SignPrepare prepares the Signer Manager to sign a document or data. If signerFile is not NULL, it will be used to define the signer file, while if NULL, the toolbox will prompt for the user’s signer file. Prompt is used to prompt the user for a signer file, if "\p", the default prompt will be used. SignPrepare returns the size of the Signature record.
  74. SignPrepare our application should  use a TRY/CATCH context to detect the following errors:
  75. kSigUserCanceled    The user cancelled this signer request. You may choose to ignore this error.    
  76. kSIGPasswordErr    The user did not enter the proper password for the designated signer file.    
  77. kSIGSignerNotValid    The signer file is not valid; perhaps it has expired.    
  78.  
  79. void                ShowSigner(void);
  80. After your application has successfully verified a file or object, ShowSigner may be used to display the entire distinguished name of the object’s or file’s signer. Your TRY/CATCH context should catch the following error: 
  81. kSIGOperationIncompatibleErr    ShowSigner is valid only after verification; it cannot be used after signing an object or file. See the signed object demo for an example of how a button that controls this request may be enabled or disabled as needed.    
  82.  
  83. void                GetSignerInfo(
  84.     SIGSignerInfo        *signerInfo
  85. );
  86. After successfully signing or verifying an object or file, you can call this method to copy information about the signer to your buffer. The buffer should be in locked memory. 
  87. Boolean            GetCertInfo(
  88.     unsigned long        certIndex,
  89.     SIGCertInfo        *certInfo
  90. );
  91. GetCertInfo can be used to iterate through the certificates that make up a signature. It returns TRUE if it finds a certificate for this index, FALSE if the index is out of range, and fails on other errors. It may be called only after successfully signing or verifying an object or file.
  92. Boolean            GetCertNameAttributes(
  93.     unsigned long        certIndex,
  94.     unsigned long        attributeIndex,
  95.     SIGNameAttributesInfo *attributeInfo
  96. );
  97. GetCertInfo can be used to iterate through the attributes for a certificate. It returns TRUE if successful, FALSE if the certIndex is out of range, and raises an error condition on other errors. It may be called only after successfully signing or verifying an object or file.
  98. Protected Methods
  99. void                InitDefaultStatusProc(
  100.     ConstStr255Param    actionString,
  101.     ConstStr255Param    objectString
  102. );
  103. This is called if you pass gSIGStatusProc to SignFile, VerifyFile, etc. It creates a SIGStatusManager object which displays the status window.
  104. void                DisposeDefaultStatusProc(void)
  105. Dispose of the status window.
  106. SIGStatusManager
  107. Introduction
  108. SIGStatusManager manages the status window that is displayed when an application selects the default status procedure. It is created and managed by the CSignature instance: your application will normally not be concerned with it.
  109. Heritage
  110. Superclass    CDirector
  111. Subclasses    none
  112. Instance Variables
  113. Variable    Type    Description
  114. itsTickCount    unsigned long    This is used to time the “barber pole” progress indicator.
  115. Static Variables
  116. Variable    Type    Description
  117. gContinueSigning Boolean    This is set TRUE when signing begins, and is set FALSE if the user clicks on the Cancel button. The value is passed to the Digital Signature Manager by the default status procedure.
  118. Methods
  119. Construction and destruction methods
  120. void                ISIGStatusManager(
  121.     ConstStr255Param    actionString,
  122.     ConstStr255Param    objectString
  123. );
  124. Create the status window (this uses some private classes that are defined in SIGStatusManager.c). The actionString and objectString are concatenated and displayed in the window. These might typically be “Signing “ “Signed File.”
  125. Operational methods
  126. void                DoCommand(
  127.     long                aCommand
  128. );
  129. The status window has a cancel button: look for it and take appropriate action by setting gContinueSigning FALSE and passing the cancel command to the manager’s superclass.
  130. void                Dawdle(
  131.     long                *maxSleep
  132. );
  133. TCL calls this repeatedly to manage the progress indicator.
  134. CSignedObject
  135. Introduction
  136. CSignedObject lets you sign and verify the contents of an individual data object, such as a spreadsheet value or the position of an object in a drawing application. You can then store and recover the signature record as part of your application’s normal storage process.
  137. Heritage
  138. Superclass    CSignature
  139. Subclasses    none
  140. Instance Variables
  141. Variable    Type    Description
  142. itsSignature    SIGSignaturePtr    The signature record, if any.
  143. itsSignatureSize    Size    The size of the signature record.
  144. Using CSignedObject
  145. Your application should create a subclass of CSignedObject for all objects that need data-specific signature processing.
  146. Methods
  147. Except as shown, all methods use the Failure mechanism (as described in <Exceptions.h> to report errors. In most cases, this means that your application must establish a TRY/CATCH context when calling these methods:
  148. kSIGUserCanceled    The user cancelled this sign or verify request. You may choose to ignore this error.    
  149. kSIGPasswordErr    The user entered an incorrect password.    
  150. kSIGSignerNotValidErr    The signer file is not valid; perhaps it has expired.    
  151. kSIGNoSignature    Programming error: your application called Sign or Verify without having called SignPrepare or VerifyPrepare.    
  152. kSIGVerifyFailedErr    Verification failed.    
  153. kSIGInvalidCredentialErr    Verification succeeded, but credentials are invalid; perhaps they have expired.    
  154. kSigSignerErr    Some sort of error with the signer: the signature is not valid.    
  155.  Construction and destruction methods
  156. void                ISignedObject(void);
  157. Initialize the private variables.
  158. void                Dispose(void);
  159. Delete any context and signature and dispose of the CSignature object.
  160. Signing and Verifying Methods
  161. Size                SignPrepare(
  162.     const FSSpec        *signerFile,
  163.     ConstStr255Param    *prompt
  164. );
  165. Override CSignature::SignPrepare to store the signature size.
  166. void                Sign(
  167.     SIGStatusProcPtr    statusProc
  168. );
  169. Sign completes the digital signature process. To sign an object, you should call SignPrepare, ProcessData, and then Sign. The statusProc, if not NULL, may be used to inform the user that a signature operation is occurring.  Errors are reported using the Failure mechanism.
  170. void                VerifyPrepare(
  171.     SIGStatusProcPtr    statusProc
  172. );
  173. Begin the process of verifying a digital signature process. To verify an object, you should call VerifyPrepare, ProcessData, then Verify. Errors are reported using the Failure mechanism.
  174. void                Verify(void);
  175. Verify completes the digital signature verification. Errors are reported using the Failure mechanism.
  176. void                ProcessData(
  177.     const void        *dataPtr,
  178.     Size                dataSize
  179. );
  180. Compute or verify a Digital Signature. This is called for all data elements. 
  181. Signature Methods
  182. Size                GetSignatureSize(void);
  183. Return the size of the signature record, as specified—originally—by SignPrepare.
  184. void                NewSignature(void);
  185. Create a signature record using the currently-specified size.
  186. void                DisposeSignature(void);
  187. Dispose of the current signature buffer, if any, but do not dispose of the context.
  188. Boolean            HasSignature(void);
  189. Return TRUE if there is a current signature.
  190. void                CheckForSignature(void);
  191. Fail with an error (kSIGNoSignature) if the application hasn’t established a signature record.
  192. void                CopySignatureToUserBuffer(
  193.     void                *buffer,
  194.     Size                bufferSize
  195. );
  196. Copy the current signature to the user’s buffer. BufferSize is the size of the user’s buffer; a paramErr error condition will be raised if bufferSize cannot hold the entire signature.
  197. void                MakeSignatureFromUserBuffer(
  198.     void                *buffer,
  199.     Size                bufferSize
  200. );
  201. Create a signature record using the information in the user’s buffer. CopySignatureToUserBuffer and MakeSignatureFromUserBuffer may be used together to save and restore object signatures.
  202. void                ReadSignature(
  203.     CDataFile            *aFile
  204. );
  205. Read a signature record from the indicated file. If a non-null signature was read, create it from the given data. The actual data includes a header record that indicates that the data is a signature and specifies its length.
  206. void                WriteSignature(
  207.     CDataFile            *aFile
  208. );
  209. Write a signature to an open file. This might be called as part of your “save this object” process. aFile is a TCL data file. This also writes a header record with the signature length: if it is called when there no signature record, it will write a zero-length record that ReadSignature correctly interprets.
  210. CSignedDataFile
  211. Introduction
  212. CSignedDataFile lets you sign and verify the contents of an entire file.
  213. Heritage
  214. Superclass    CSignature
  215. Subclasses    none
  216. Using CSignedDataFile
  217. Use this as part of your application’s Open and Close document processing.
  218. Methods
  219. Except as shown, all methods use the Failure mechanism (as described in <Exceptions.h> to report errors. In certain cases, this means that your application must establish a TRY/CATCH context when calling these methods.    
  220. Construction and destruction methods
  221. void                ISignedDataFile(void);
  222. Initalize the object instance.
  223. void                SignFile(
  224.     const FSSpec        *signerFile,
  225.     ConstStr255Param    promptString,
  226.     const FSSpec        *dataFile,
  227.     SIGStatusProcPtr    statusProc
  228. );
  229. Sign the file specified by dataFile. If signerFile is not NULL, it will be used to define the signer file, while if NULL, the toolbox will prompt for the user’s signer file. Prompt is used to prompt the user for a signer file, if "\p", the default prompt will be used. SignPrepare returns the size of the Signature record. StatusProc defines the user status procedure. Use gSIGStatusProc for the default window. 
  230. Because of the way the Think Class Library closes files, you should call SignFile in the following sequence:
  231. 1    Create a copy of the FSSpec associated with the file.
  232. 2    Write all data and close the file. You can delete the CDataFile object at this time.
  233. 3    SignFile using the saved FSSpec.
  234. 4    Call DisposeSignerContext
  235. You should call SignPrepare…SignFile in a TRY/CATCH context, checking for the following errors:
  236. kSIGUserCanceled    The user cancelled this signer request. You may choose to ignore this error.    
  237. kSIGPasswordErr    The user entered an incorrect password.    
  238. kSIGSignerNotValid    The signer file is incorrect.    
  239. wrPermErr    The data file is marked read-only (perhaps it was already signed?)    
  240. void                VerifyFile(
  241.     const FSSpec        *dataFile,
  242.     SIGStatusProcPtr    statusProc
  243. );
  244. Verify the signature in the file specified by dataFile.  StatusProc defines the user status procedure. Use gSIGStatusProc for the default window. You should call VerifyFile in a TRY/CATCH context, checking for the following errors:
  245. kSIGUserCanceled    The user cancelled this verification request. You may choose to ignore this error.    
  246. kSIGVerifyFailedErr    Verification failed: the file or signature may have been changed.    
  247. kSIGInvalidCredentialErr    Verification succeeded, but the credentials are pending or have expired. The context is still active.    
  248. Boolean            FileIsSigned(
  249.     const FSSpec        *dataFile,
  250. );
  251. Return TRUE if the specified file has a signature. Note that the signature is not verified.
  252. æ◊#ˇ ˇˇˇˇ#◊ 
  253. d, Palatino
  254. .+Z.Digital Signature Demo(.1).
  255. °dONLNd5\NÀ(fzDIGITAL SIGNATURE DEMO,     Helvetica
  256. °dONLNdNÿ]O+| MARTIN MINOW°dONLNd$\êkó(ÜÆDEVELOPER TECHNICAL SUPPORT°dONLNd@É<íì(≠Z Introduction
  257. °dONLNdMù<´¥*AThe Digital Signature Demo illustrates how AOCE Digital Signature°dONLNdè´<πÏ*Jtechnology may be incorporated into an existing application with a minimum°dONLNd⁄π<«–*Lof fuss, and without significantly perturbation of the existing application.°dONLNd'Õ<€…*DThe demo extends the Think Class Library “Tiny Edit” sample program,°dONLNdl€<È·*Kallowing documents created by TinyEdit to be “signed” and “verified” by the°dONLNd∏È<˜«*FDigital Signature Manager. It also shows how Digital Signatures may be°dONLNdˇ˜<„*Oapplied to application data, such as the state of checkboxes and radio buttons.°dONLNdO <È*NAlthough the class is defined for, and operates within the Think Class Library°dONLNdû<'‡*Qorganizational structure, it should be relatively easy to adapt it to other class°dONLNd'<5∏*Fhierarchies. Even if you do not use a class library design in your own°dONLNd75<C‡*Napplications, you should still be able to use the demo as a basis for your own°dONLNdÜC<Q*%Digital Signature subroutine library.
  258. °dONLNd¨]<lÆ*Class Hierarchy
  259. °dONLNdºw<Ö»*GThe demo defines a CSignature class and two subclasses that are used to°dONLNdÖ<ì◊*Mmanipulate digital signatures. It also adds a few simple classes that add the°dONLNdRì<°™*Fnecessary capabilities to TinyEdit. The class hierarchy is as follows:°dONLNdô¢<∞X*Class°dONLNd†¢‰∞$)® Description"¿U#"¿Vv"¿Õ"¿Œ."¿˝ ¿˛¿("¿)#"¡U
  260. "¡˝
  261. "¡)
  262. ,
  263. Courier°dONLNd≠π<≈Ç(‚Z
  264. CSignature°dONLNdπ∑‰≈(‡6The base class for Digital Signatures. CSignature is a°dONLNd≈‰”Á*1subclass to the base-class, CObject. Applications°dONLNd"”‰·Ú*3normally do not create instances of this class, but°dONLNdV·‰ÔY*rather use subclasses."œU"œVv"œÕ"œŒ."œ˝ œ˛œ("œ)"–U="–˝="–)=°dONLNdo¯TΩ(!rCSignedDataFile°dONLNdˆ‰˛(6This class allows signing or verifying an entire file.°dONLNd∂‰ˇ*5It is used to sign a document after it has been saved°dONLNdω ˚*3to disk, and to verify an existing signed document."U"V"m"n^"Õ"Œ."˝ ˛(")"U/"˝/")/°dONLNd")T5Ø(Rr
  265. CSignedObject°dONLNd0'‰5˙(P5This class allows signing or verifying a data object.°dONLNdf5‰C¯*2Your application should create a subclass with the°dONLNdôC‰Q˜*/necessary content and methods. You can then use°dONLNd…Q‰_*4CSignedObject methods to sign or verify the object’s°dONLNd˛_‰m"* actual data."?U"?V"?m ?n?¸"?˝ ?˛?("?)"@UK"åU"åm ånå¸"@˝K"å˝ å˛å("@)K"å)
  266. °dONLNd z<â¥(§ZSample Program
  267. °dONLNdî<¢◊*HThe sample program is an extension of the Think Class Library “TinyEdit”°dONLNdd¢<∞÷*Ksample application. It extends the CEditDoc class to provide for signed and
  268. *&:Copyright © 1993, Apple Computer Inc. All Rights Reserved.(Ò??ˇ
  269. ƒ◊#ˇ ˇˇˇˇ#◊ 
  270. d, Palatino
  271. .+Z.Digital Signature Demo(.2).°dONLNd)<7Ï(RZOverified text files and adds a sample class to show how you can sign and verify°dONLNdP7<E“*Jthe contents of a dialog. The demo requires the following source files and°dONLNdõE<Sà*their headers:°dONLNd™STai+File°dONLNdØSa0)ú Description°dONLNdªaToŸ(ärDigitalSignatureDemo.c°dONLNd“aoΩ)ú&This is the main program. It creates a°dONLNd˘o}I*DemoApp class.°dONLNd}Tãñ(¶r    DemoApp.c°dONLNd}ã€)ú,This is a subclass to CEditApp that lets you°dONLNd?ãôË*+open signed documents and starts the signed°dONLNdkôß„*+object demo. It also overrides a “shutdown”°dONLNdóßµ„*+method to ensure that the signature context°dONLNd√µ√◊*&has been removed when your application°dONLNdÍ√— *exits.°dONLNdÒ—Tfl©(˙r
  272. DemoEditDoc.c°dONLNdˇ—flÿ)ú,This is a subclass to CEditDoc that lets you°dONLNd,flÌ¡*&sign and verify documents. It also has°dONLNdSÌ˚Õ*$methods override CEditDoc methods in°dONLNdx˚    ≈*'order to provide better error messages.°dONLNd†    TΔ(2rDemoSignedObject.c°dONLNd≥    ¬)ú(This object can sign and verify its data°dONLNd‹%’*,contents. It is a subclass to CSignedObject.°dONLNd    %T3Í(NrDemoSignedObjectDialog.c°dONLNd"%3ÿ)ú&This dialog manages a DemoSignedObject°dONLNdI3A–*,instance. It displays a dialog that lets you°dONLNdvAOË*,change checkbox and text items, and controls°dONLNd£O]·*+signing, verifying, and other CSignedObject°dONLNdœ]k‚*-functions. It is a subclass to CDLOGDirector.°dONLNd˝ky€**Although it appears to the user as a modal°dONLNd(yá¿*'dialog, it is actually implemented as a°dONLNdPáïN*normal window.°dONLNd_ïT£ß(ærErrorMessage.c°dONLNdnï£ª)ú%This file contains two simple display°dONLNdî£±·**functions for debugging convenience. Error°dONLNdø±øÊ*)messages were included within the program°dONLNdÈøÕË*/text so there was a single reference point that°dONLNdÕ€Δ*%explains errors. A production program°dONLNd?€È„*-should preferably store its error messages in°dONLNdmÈ˜9*resource files°dONLNd|˜T√( rSIGStatusManager.c°dONLNdè˜€)ú(This contains the status window manager,°dONLNd∏Ï*(window, and window contents. This window°dONLNd·!’**is displayed when you specify the built-in°dONLNd !/Í*-status window for a Sign or Verify operation.°dONLNd:/T=ÿ(XrSystemSupportsAOCE.c°dONLNdO/=‚)ú-This subroutine tests for the presence of the°dONLNd}=K»*(AOCE toolbox. It returns an error if the°dONLNd¶KY‘**toolbox was not installed or was disabled.,     Helvetica
  273. °dONLNd—e<tƒ(èZPotential Problems
  274. °dONLNd‰<ç·*KThere are a few things that application developers need to be aware of when°dONLNd0ç<õü*@using Digital Signatures (these are independent of the example):
  275. *;:Copyright © 1993, Apple Computer Inc. All Rights Reserved.(Ò??ˇΔ◊#ˇ ˇˇˇˇ#◊ 
  276. d, Palatino
  277. .+Z.Digital Signature Demo(.3).°dONLNd3`Ag(\~•°dONLNd3mA%)
  278.  When your application exits, be °dONLNd"3%A»)∏sure that you have disposed°dONLNd>AmOÇ(jã1of the signing context (SIGContextPtr datum). In °dONLNdoAÇO»(j†
  279. general, this°dONLNd}Om]W(xã)means that your application should patch °dONLNd¶OW]»)Íthe ExitToShell trap°dONLNdª]mkµ(Üã
  280. with a small °dONLNd»]µk»)H1subroutine that checks for an active context. The°dONLNd˙kmyi(îã-sample program stores the context pointer in °dONLNd'kiy»)¸a global variable,°dONLNd:ymá(¢ã-and overrides CApplication::RemovePatches to °dONLNdgyá»(¢ù
  281. check that it°dONLNduámï`(∞ã,has been deleted when the application exits.°dONLNd¢ü`≠g(»~•°dONLNd§üm≠)
  282. Signing and verifying take °dONLNdøü≠»)ñ$a fairly long time; your application°dONLNd‰≠mªÂ(÷ãshould use a status °dONLNd¯≠ª»)x%procedure to entertain the user while°dONLNdªm…º(‰ãsigning. This °dONLNd,ªº…»)O0entails a bit of effort: you should not initiate°dONLNd]…m◊(Úãsigning or verifying from a °dONLNdy…◊»)®Modal Dialog, but should use°dONLNdñ◊mÂæ(ã
  283. some form of °dONLNd£◊æÂ»)Q+“standard” window or a non-modal dialog. In°dONLNdœÂmÛ(ãthe example, the signed object °dONLNdÓÂÛ»)Ædemo uses a subclass of TCL’s°dONLNd Ûm¡(ãCDialog class, °dONLNdÛ¡»)T)which implements a modal-dialog lookalike°dONLNdEmç(*ã.using the normal window-based event loop. The °dONLNdsç»(*´
  284. reason for°dONLNd~m«(8ãthis is that your °dONLNdê«»)Z-status callback should call your normal event°dONLNdæm+ô(Fã    loop: if °dONLNd«ô+»),4you have an active modal dialog, it will not receive°dONLNd¸+m9(Tãupdate events properly.°dONLNdC`Qg(l~•°dONLNdCmQ
  285. )
  286. When a file is signed, it is °dONLNd3C
  287. Q»)†"set “locked,” i.e., read-only This°dONLNdVQm_æ(zã means that     °dONLNdaQæ_»)Q'your application must open it read-only°dONLNdâ_mm8(àã$(fsRdPerm). Also, your users cannot °dONLNd≠_8m»)Àcreate a new file with the°dONLNd»mm{º(ñã5same name without first, manually, renaming the file °dONLNd˝mº{»(ñ⁄or°dONLNd{mâÒ(§ãplacing it into the trash.°dONLNdì`°g(º~•°dONLNdìm°π)
  288. The method °dONLNd(ìπ°»)L/descriptions only describe the errors that your°dONLNdX°mØ¥( ã application °dONLNdd°¥Ø»)G*needs to handle (because they’re benign or°dONLNdèØmΩ®(ÿã expected). °dONLNdöØ®Ω»);.However, note that there are a number of other°dONLNd…ΩmÀl(Êã*Digital Signature Manager errors that may °dONLNdÛΩlÀ»)ˇalso occur. You°dONLNdÀmŸó(Ùãshould °dONLNd
  289. ÀóŸ»)*8carefully test your application to make sure it displays°dONLNdCŸmÁz(ã0informative error messages in all circumstances.°dONLNduÒmˇd*&There are a number of instances where °dONLNdõÒdˇ»)˜errors should be°dONLNd¨ˇm
  290. ≤((ã detected in °dONLNd∏ˇ≤
  291. »)E/your application. For example, signed files are°dONLNdË
  292. m•(6ã
  293. read-only °dONLNdÚ
  294. •»)81(“locked”) and must be opened with permission set°dONLNd$m)
  295. (Dãto fsRdPerm, rather than °dONLNd=
  296. )»)ùthe standard fsRdWrPerm. You°dONLNdZ)m7ü(Rã8should search the demo for Message() calls to see those °dONLNdí)ü7»(RΩerrors I°dONLNdõ7mEÏ(`ãfound worth detecting.°dONLNd≥K<Y§(tZ@The remainder of this document describes the individual classes.
  297. *}:Copyright © 1993, Apple Computer Inc. All Rights Reserved.(Ò??ˇ ¿◊#ˇ ˇˇˇˇ#◊ 
  298. d, Palatino
  299. .+Z.Digital Signature Demo(.4).,     Helvetica
  300. °dONLNd5<Dç(_Z
  301. CSignature°dONLNd I<Xì* Introduction
  302. °dONLNd]<k¬*JCSignature is the base class for Digital Signature processing. It contains°dONLNdck<y‰*Pmethods that all Digital Signature processing requires, as well as a few utility°dONLNd¥y<áË*Oclasses. Your application does not use CSignature directly, but rather uses one°dONLNdá<ïò*of its sub-classes.
  303. °dONLNdõ<™z*Heritage
  304. °dONLNd!©T∑é+
  305. Superclass°dONLNd,©∫∑‰)fCObject°dONLNd4∑T≈ç(‡r
  306. Subclasses°dONLNd?∑∫≈l)fCSignedDataFile, CSignedObject
  307. °dONLNd^À<⁄≥(ıZGlobal Variables
  308. °dONLNdoŸTÁÉ+
  309. Variable°dONLNdxŸ∫Á’)fType°dONLNd}Ÿ8Áx)~ Description°dONLNdâÁTı®(rgSIGStatusProc°dONLNdòÁ∫ı)fSIGStatusProcPtr°dONLNd©Á8ı‹)~Default status procedure: pass°dONLNd»ı8Á*#this to Sign, SignFile, etc. to use°dONLNdÏ8µ*the built-in procedure.°dONLNdT©(:rgSIGContextPtr°dONLNd∫    )f
  310. SIGContextPtr°dONLNd!8Ë)~The Signer Manager context. Be°dONLNd@8-«*sure that your application°dONLNd[-8;Ê*!disposes of any context before it°dONLNd};8Iw* terminates.
  311. °dONLNdâO<^∂(yZGlobal Functions,
  312. Courier
  313. °dONLNdöcTop+void°dONLNd¢cÃoâ)xDisposeSignerContext(void);°dONLNdæu<É≈(ûZJDispose of the signer context, if it exists. This must be called when your°dONLNd    É<ëv*:application exits (you should trap ExitToShell so you call°dONLNdDë<üp*7DisposeSignerContext even if your application crashes).
  314. °dONLNd|•<¥¬*Instance Variables
  315. °dONLNdè≥T¡É+
  316. Variable°dONLNdò≥∫¡’)fType°dONLNdù≥8¡x)~ Description°dONLNd©¡Tœß(ÍritsContextType°dONLNd∏¡∫œ
  317. )f
  318. unsigned long°dONLNdΔ¡8œ⁄)~This is the type of the context°dONLNdÊœ8›’*variable: it is needed only by°dONLNd›8ÎÍ*methods that enable/disable the°dONLNd%Î8˘À*ShowSigner option as that°dONLNd?˘8¡*option is valid only after°dONLNdZ8Δ*verifying an object or file.°dONLNdwT#¥(>ritsStatusManager°dONLNdà∫#!)fSIGStatusManager°dONLNdô8#…)~An instance of this class is°dONLNd∂#81È*"created if you specify the default°dONLNdŸ18?å*status window.
  319. °dONLNdËE<Tz(oZMethods
  320. °dONLNdY<g*$Construction and destruction methods°dONLNdmTyp+void°dONLNdmÃyC)xISignature(void);°dONLNd/<çÊ(®Z!Initialize the private variables.°dONLNdQìTüp+void°dONLNdYìÃü.)xDispose(void);
  321. (ÒZ:Copyright © 1993, Apple Computer Inc. All Rights Reserved.(Ò??ˇ
  322. n◊#ˇ ˇˇˇˇ#◊ 
  323. d, Palatino
  324. .+Z.Digital Signature Demo(.5).°dONLNd/<=æ(XZFDelete any context and signature and dispose of the CSignature object.°dONLNdGC<Q¬*Signer Context Methods,
  325. Courier°dONLNd^WTcp+void°dONLNdeW¥c)` NewContext(°dONLNdrclo«(åä
  326. unsigned long°dONLNdÅc‰o1)x contextType°dONLNdçoT{b(òr);°dONLNdêÅ<èÈ(™ZLCreate a new context of the indicated type. The contextType parameter may be°dONLNd›è<ùΔ*Fone of the following values, which are defined in <DigitalSignature.h>°dONLNd$ùN´Ç+kSIGSign°dONLNd-ù∫´5)lSigning a file or object°dONLNdF´Nπå(‘l
  327. kSIGVerify°dONLNdQ´∫π?)lVerifying a file or object°dONLNdlπN«ã(‚l
  328. kSIGDigest°dONLNdwπ∫«^)lPreparing a digest of an object°dONLNdóÕTŸp(ˆrvoid°dONLNdüÕßf)xCheckForContext(void);°dONLNd∂fl<Ì·(ZLFail if there is no current context with a kSIGContextPrepareErr. This would°dONLNdÌ<˚Δ*Findicate a programming error where one of the routines that requires a°dONLNdJ˚<    Ï*Lcontext was called when there was no context. For example, calling Sign when°dONLNdó    <≥*Eyour application hasn’t called SignPrepare, would cause this failure.°dONLNd›T)Ø+
  329. unsigned long°dONLNdÏÃ)_)xGetContextType(void);°dONLNd/<=Õ(XZLReturn zero if there is no current context, else the type that was specified°dONLNdO=<KE*-when the application called NewSignerContext.°dONLNd}Q<_¶*Signature Methods°dONLNdèeTqp+Size°dONLNdóeÃq )x SignPrepare(°dONLNd•ql}¿(öä const FSSpec°dONLNd≥q‰}8)x *signerFile,°dONLNd¡}lâ‹(¶äConstStr255Param°dONLNd“}‰â)x*prompt°dONLNd⁄âTïb(≤r);°dONLNd›õ<©≈(ƒZFSignPrepare prepares the Signer Manager to sign a document or data. If°dONLNd$©<∑Î*QsignerFile is not NULL, it will be used to define the signer file, while if NULL,°dONLNdv∑<≈Ÿ*Lthe toolbox will prompt for the user’s signer file. Prompt is used to prompt°dONLNd√≈<”Ë*Qthe user for a signer file, if "\p", the default prompt will be used. SignPrepare°dONLNd”<·*)returns the size of the Signature record.°dONLNd?Á<ı‚*ISignPrepare our application should  use a TRY/CATCH context to detect the°dONLNdâı<ô*following errors:°dONLNdõ <¨*kSigUserCanceled°dONLNd¨    ∏(22The user cancelled this signer°dONLNdÀ%“*!request. You may choose to ignore°dONLNdÌ%3K* this error.°dONLNd˙;<G•(dZkSIGPasswordErr°dONLNd
  330. 9GÕ(b2!The user did not enter the proper°dONLNd,GU”*"password for the designated signer°dONLNdOUc)*file.°dONLNdVk<w∫(îZkSIGSignerNotValid°dONLNdiiw„(í2(The signer file is not valid; perhaps it°dONLNdíwÖV* has expired.°dONLNd°ùT©p(Δrvoid°dONLNd©ùéC)xShowSigner(void);
  331. (ÒZ:Copyright © 1993, Apple Computer Inc. All Rights Reserved.(Ò??ˇ
  332. Æ◊#ˇ ˇˇˇˇ#◊ 
  333. d, Palatino
  334. .+Z.Digital Signature Demo(.6).°dONLNd/<=⁄(XZMAfter your application has successfully verified a file or object, ShowSigner°dONLNdN=<K›*Nmay be used to display the entire distinguished name of the object’s or file’s°dONLNdùK<Y≤*@signer. Your TRY/CATCH context should catch the following error:,
  335. Courier°dONLNdfla<m*kSIGOperationIncompatibleErr°dONLNd¸_mº(à2ShowSigner is valid only after°dONLNdm{‘*%verification; it cannot be used after°dONLNdA{â√*"signing an object or file. See the°dONLNddâó‚*$signed object demo for an example of°dONLNdâó•ø*how a button that controls this°dONLNd©•≥·*%request may be enabled or disabled as°dONLNdœ≥¡?*needed.°dONLNdŸŸTÂp(rvoid°dONLNd·ŸÃÂ.)xGetSignerInfo(°dONLNdÒÂlÒ«(ä
  336. SIGSignerInfo°dONLNd‰Ò1)x *signerInfo°dONLNd ÒT˝b(r);°dONLNd<≈(,ZLAfter successfully signing or verifying an object or file, you can call this°dONLNd\<≈*Fmethod to copy information about the signer to your buffer. The buffer°dONLNd£<-fi*should be in locked memory.°dONLNd¿3T?Ö+Boolean°dONLNd 3Ã? )x GetCertInfo(°dONLNdÿ?lK«(hä
  337. unsigned long°dONLNdÁ?‰K*)x
  338. certIndex,°dONLNdÛKlWπ(tä SIGCertInfo°dONLNdK‰W#)x    *certInfo°dONLNd
  339. WTcb(Är);°dONLNd
  340. i<wÃ(íZJGetCertInfo can be used to iterate through the certificates that make up a°dONLNdXw<Öfi*Qsignature. It returns TRUE if it finds a certificate for this index, FALSE if the°dONLNd™Ö<ìÃ*Mindex is out of range, and fails on other errors. It may be called only after°dONLNd¯ì<°I*4successfully signing or verifying an object or file.°dONLNd-ßT≥Ö+Boolean°dONLNd7ßÃ≥f)xGetCertNameAttributes(°dONLNdO≥lø«(‹ä
  341. unsigned long°dONLNd^≥‰ø*)x
  342. certIndex,°dONLNdjølÀ«(Ëä
  343. unsigned long°dONLNdyø‰ÀM)xattributeIndex,°dONLNdäÀl◊h(Ùä$SIGNameAttributesInfo *attributeInfo°dONLNdØ◊T„b(r);°dONLNd≤È<˜“(ZOGetCertInfo can be used to iterate through the attributes for a certificate. It°dONLNd˜<‡*Nreturns TRUE if successful, FALSE if the certIndex is out of range, and raises°dONLNdQ<–*Lan error condition on other errors. It may be called only after successfully°dONLNdû<!*'signing or verifying an object or file.,     Helvetica
  344. °dONLNdΔ'<6ƒ*Protected Methods
  345. °dONLNdÿ;TGp+void°dONLNd‡;ÃGf)xInitDefaultStatusProc(°dONLNd¯GlS‹(päConstStr255Param°dONLNd    G‰S?)x
  346. actionString,°dONLNdSl_‹(|äConstStr255Param°dONLNd)S‰_8)x objectString°dONLNd6_Tkb(àr);°dONLNd9q<È(öZTThis is called if you pass gSIGStatusProc to SignFile, VerifyFile, etc. It creates a°dONLNdé<çá*9SIGStatusManager object which displays the status window.°dONLNd»ìTüp+void°dONLNd–ìÃüû)xDisposeDefaultStatusProc(void)
  347. (ÒZ:Copyright © 1993, Apple Computer Inc. All Rights Reserved.(Ò??ˇ ö◊#ˇ ˇˇˇˇ#◊ 
  348. d, Palatino
  349. .+Z.Digital Signature Demo(.7).°dONLNd/<=·(XZDispose of the status window.,     Helvetica
  350. °dONLNdI<X≈*SIGStatusManager°dONLNd/]<lì* Introduction
  351. °dONLNd<q<–*DSIGStatusManager manages the status window that is displayed when an°dONLNdÅ<çfi*Napplication selects the default status procedure. It is created and managed by°dONLNd–ç<õ“*Hthe CSignature instance: your application will normally not be concerned°dONLNdõ<©d*with it.
  352. °dONLNd"Ø<æz*Heritage
  353. °dONLNd+ΩTÀé+
  354. Superclass°dONLNd6Ω∫ÀÔ)f    CDirector°dONLNd@ÀTŸç(Ùr
  355. Subclasses°dONLNdKÀ∫Ÿ◊)fnone
  356. °dONLNdPfl<Ó¬(    ZInstance Variables
  357. °dONLNdcÌT˚É+
  358. Variable°dONLNdlÌ∫˚’)fType°dONLNdqÌ8˚x)~ Description°dONLNd}˚T    ú($r itsTickCount°dONLNdä˚∫    
  359. )f
  360. unsigned long°dONLNdò˚8    Â)~ This is used to time the “barber°dONLNdπ    8ø*pole” progress indicator.
  361. °dONLNd”<,≠(GZStatic Variables
  362. °dONLNd‰+T9É+
  363. Variable°dONLNdÌ+∫9’)fType°dONLNdÚ+89x)~ Description°dONLNd˛9TGÎ(brgContinueSigning Boolean°dONLNd98G„)‰This is set TRUE when signing°dONLNd5G8U›*begins, and is set FALSE if the°dONLNdUU8cÎ*!user clicks on the Cancel button.°dONLNdwc8q«*The value is passed to the°dONLNdíq8Ÿ*Digital Signature Manager by°dONLNdØ8ç’*the default status procedure.
  364. °dONLNdÕì<¢z(ΩZMethods
  365. °dONLNd’ß<µ*$Construction and destruction methods,
  366. Courier°dONLNd˙ªT«p+void°dONLNdªÃ«J)xISIGStatusManager(°dONLNd«l”‹(äConstStr255Param°dONLNd'«‰”?)x
  367. actionString,°dONLNd6”lfl‹(¸äConstStr255Param°dONLNdG”‰fl8)x objectString°dONLNdTflTÎb(r);°dONLNdWÒ<ˇ€(ZLCreate the status window (this uses some private classes that are defined in°dONLNd§ˇ<
  368. Ê*KSIGStatusManager.c). The actionString and objectString are concatenated and°dONLNd
  369. <fi*Kdisplayed in the window. These might typically be “Signing “ “Signed File.”°dONLNd<!</≤*Operational methods°dONLNdP5TAp+void°dONLNdX5ÃA)x
  370. DoCommand(°dONLNddAlMà(jälong°dONLNdlA‰M)xaCommand°dONLNduMTYb(vr);°dONLNdx_<mÈ(àZNThe status window has a cancel button: look for it and take appropriate action°dONLNd«m<{fl*Gby setting gContinueSigning FALSE and passing the cancel command to the°dONLNd{<â≥*manager’s superclass.°dONLNd%èTõp+void°dONLNd-èÃõ˝)xDawdle(°dONLNd6õlßà(ƒälong°dONLNd>õ‰ß#)x    *maxSleep
  371. (ÒZ:Copyright © 1993, Apple Computer Inc. All Rights Reserved.(Ò??ˇ ú◊#ˇ ˇˇˇˇ#◊ 
  372. d, Palatino
  373. .+Z.Digital Signature Demo(.8).,
  374. Courier°dONLNd)T5b(Rr);°dONLNd;<I}(dZ;TCL calls this repeatedly to manage the progress indicator.,     Helvetica
  375. °dONLNd?U<d®*
  376. CSignedObject°dONLNdMi<xì* Introduction
  377. °dONLNdZ}<ãœ*ICSignedObject lets you sign and verify the contents of an individual data°dONLNd§ã<ô⁄*Mobject, such as a spreadsheet value or the position of an object in a drawing°dONLNdÚô<ß‘*Kapplication. You can then store and recover the signature record as part of°dONLNd>ß<µ$**your application’s normal storage process.
  378. °dONLNdiª< z*Heritage
  379. °dONLNdr…T◊é+
  380. Superclass°dONLNd}…∫◊¯)f
  381. CSignature°dONLNdà◊TÂç(r
  382. Subclasses°dONLNdì◊∫Â◊)fnone
  383. °dONLNdòÎ<˙¬(ZInstance Variables
  384. °dONLNd´˘TÉ+
  385. Variable°dONLNd¥˘∫’)fType°dONLNdπ˘8x)~ Description°dONLNd≈Tó(0r itsSignature°dONLNd“∫)fSIGSignaturePtr°dONLNd‚8”)~The signature record, if any.°dONLNdT#Æ(>ritsSignatureSize°dONLNd∫#—)fSize°dONLNd8#È)~!The size of the signature record.
  386. °dONLNd8)<8’(SZUsing CSignedObject
  387. °dONLNdL=<K‰*OYour application should create a subclass of CSignedObject for all objects that°dONLNdúK<Y*(need data-specific signature processing.
  388. °dONLNd≈_<nz*Methods
  389. °dONLNdÕs<Å–*GExcept as shown, all methods use the Failure mechanism (as described in°dONLNdÅ<è∞*D<Exceptions.h> to report errors. In most cases, this means that your°dONLNdZè<ù∫*Aapplication must establish a TRY/CATCH context when calling these°dONLNdúù<´p*methods:°dONLNd•≥<ø¨*kSIGUserCanceled°dONLNd∂±ø‡(⁄2&The user cancelled this sign or verify°dONLNd›øÕ“*!request. You may choose to ignore°dONLNdˇÕ€K* this error.°dONLNd „<Ô•( ZkSIGPasswordErr°dONLNd·Ô∑(
  390. 2The user entered an incorrect°dONLNd:Ô˝K*    password.°dONLNdE<œ(.ZkSIGSignerNotValidErr°dONLNd[„(,2(The signer file is not valid; perhaps it°dONLNdÑV* has expired.°dONLNdí'<3•(PZkSIGNoSignature°dONLNd¢%3‚(N2#Programming error: your application°dONLNdΔ3A‡*$called Sign or Verify without having°dONLNdÎAO‹*$called SignPrepare or VerifyPrepare.°dONLNdW<c¡(ÄZkSIGVerifyFailedErr°dONLNd%Uc|(~2Verification failed.°dONLNd;k<w‰(îZkSIGInvalidCredentialErr°dONLNdTiw©(í2Verification succeeded, but°dONLNdpwÖ›*%credentials are invalid; perhaps they°dONLNdñÖì_*
  391. have expired.
  392. (ÒZ:Copyright © 1993, Apple Computer Inc. All Rights Reserved.(Ò??ˇ ä◊#ˇ ˇˇˇˇ#◊ 
  393. d, Palatino
  394. .+Z.Digital Signature Demo(.9).,
  395. Courier°dONLNd1<=ó(ZZ
  396. kSigSignerErr°dONLNd/=”(X2#Some sort of error with the signer:°dONLNd2=K¢*the signature is not valid.°dONLNdOQ<_(zZ% Construction and destruction methods°dONLNdueTqp+void°dONLNd}eÃqX)xISignedObject(void);°dONLNdíw<ÖÊ(†Z!Initialize the private variables.°dONLNd¥ãTóp+void°dONLNdºãÃó.)xDispose(void);°dONLNdÀù<´æ(ΔZFDelete any context and signature and dispose of the CSignature object.°dONLNd±<øÎ*Signing and Verifying Methods°dONLNd0≈T—p+Size°dONLNd8≈× )x SignPrepare(°dONLNdF—l›¿(˙ä const FSSpec°dONLNdT—‰›8)x *signerFile,°dONLNdb›lÈ‹(äConstStr255Param°dONLNds›‰È)x*prompt°dONLNd{ÈTıb(r);°dONLNd~˚<    ã($Z=Override CSignature::SignPrepare to store the signature size.°dONLNdºTp+void°dONLNdƒÃÔ)xSign(°dONLNdÀl'‹(DäSIGStatusProcPtr°dONLNd‹‰'*)x
  397. statusProc°dONLNdÁ'T3b(Pr);°dONLNdÍ9<GÎ(bZPSign completes the digital signature process. To sign an object, you should call°dONLNd;G<UË*LSignPrepare, ProcessData, and then Sign. The statusProc, if not NULL, may be°dONLNdàU<c‘*Lused to inform the user that a signature operation is occurring.  Errors are°dONLNd’c<q*%reported using the Failure mechanism.°dONLNd˚wTÉp+void°dONLNdwÃÉ.)xVerifyPrepare(°dONLNdÉlè‹(¨äSIGStatusProcPtr°dONLNd$ɉè*)x
  398. statusProc°dONLNd/èTõb(∏r);°dONLNd2°<Ø·( ZPBegin the process of verifying a digital signature process. To verify an object,°dONLNdÉØ<Ω‹*Lyou should call VerifyPrepare, ProcessData, then Verify. Errors are reported°dONLNd–Ω<À„*using the Failure mechanism.°dONLNdÌ—T›p+void°dONLNdı—Û')x
  399. Verify(void);°dONLNd„<Ò‡( ZNVerify completes the digital signature verification. Errors are reported using°dONLNdRÒ<ˇ¡*the Failure mechanism.°dONLNdiTp+void°dONLNdqà)x ProcessData(°dONLNdl≤(:ä
  400. const void°dONLNdã‰#)x    *dataPtr,°dONLNdñl)à(FäSize°dONLNdû‰))xdataSize°dONLNdß)T5b(Rr);°dONLNd™;<I“(dZLCompute or verify a Digital Signature. This is called for all data elements.°dONLNd¯O<]¶*Signature Methods°dONLNd
  401. cTop+Size°dONLNdcÃom)xGetSignatureSize(void);°dONLNd*u<ɱ(ûZCReturn the size of the signature record, as specified—originally—by°dONLNdnÉ<ëÇ* SignPrepare.°dONLNd{óT£p+void°dONLNdÉóãQ)xNewSignature(void);
  402. (ÒZ:Copyright © 1993, Apple Computer Inc. All Rights Reserved.(Ò??ˇ Ù◊#ˇ ˇˇˇˇ#◊ 
  403. d, Palatino
  404. .+Z.Digital Signature Demo(.˚10) .°dONLNd/<=Å(XZ=Create a signature record using the currently-specified size.,
  405. Courier°dONLNd>CTOp+void°dONLNdFCÃOm)xDisposeSignature(void);°dONLNd^U<cƒ(~ZJDispose of the current signature buffer, if any, but do not dispose of the°dONLNd©c<qg*context.°dONLNd≤wTÉÖ+Boolean°dONLNdºwÃÉQ)xHasSignature(void);°dONLNd–â<ó/(≤Z,Return TRUE if there is a current signature.°dONLNd˝ùT©p+void°dONLNdùét)xCheckForSignature(void);°dONLNdØ<Ω€(ÿZLFail with an error (kSIGNoSignature) if the application hasn’t established a°dONLNdkΩ<Àô*signature record.°dONLNd}—T›p+void°dONLNd֗ÛÇ)xCopySignatureToUserBuffer(°dONLNd°›lÈà(ävoid°dONLNd©›‰È)x*buffer,°dONLNd≥Èlıà(äSize°dONLNdªÈ‰ı*)x
  406. bufferSize°dONLNdΔıTb(r);°dONLNd…<÷(0ZNCopy the current signature to the user’s buffer. BufferSize is the size of the°dONLNd<#◊*Muser’s buffer; a paramErr error condition will be raised if bufferSize cannot°dONLNdf#<1…*hold the entire signature.°dONLNdÅ7TCp+void°dONLNdâ7ÃCê)xMakeSignatureFromUserBuffer(°dONLNdßClOà(lävoid°dONLNdØC‰O)x*buffer,°dONLNdπOl[à(xäSize°dONLNd¡O‰[*)x
  407. bufferSize°dONLNdÃ[Tgb(Ñr);°dONLNdœm<{≤(ñZECreate a signature record using the information in the user’s buffer.°dONLNd{<â–*@CopySignatureToUserBuffer and MakeSignatureFromUserBuffer may be°dONLNdVâ<óT*4used together to save and restore object signatures.°dONLNdãùT©p+void°dONLNdìùé.)xReadSignature(°dONLNd£©lµ´(“ä    CDataFile°dONLNdØ©‰µ)x*aFile°dONLNd∂µT¡b(fir);°dONLNdπ«<’Ÿ(ZLRead a signature record from the indicated file. If a non-null signature was°dONLNd’<„⁄*Mread, create it from the given data. The actual data includes a header record°dONLNdT„<Òù*Ethat indicates that the data is a signature and specifies its length.°dONLNdö˜Tp+void°dONLNd¢˜Ã5)xWriteSignature(°dONLNd≥l´(,ä    CDataFile°dONLNdø‰)x*aFile°dONLNdΔTb(8r);°dONLNd…!</⁄(JZMWrite a signature to an open file. This might be called as part of your “save°dONLNd/<=Ÿ*Pthis object” process. aFile is a TCL data file. This also writes a header record°dONLNdh=<KÍ*Rwith the signature length: if it is called when there no signature record, it will°dONLNdªK<Yß*Cwrite a zero-length record that ReadSignature correctly interprets.,     Helvetica
  408. °dONLNdˇe<t∂*CSignedDataFile°dONLNdy<àì* Introduction
  409. °dONLNdç<õæ*HCSignedDataFile lets you sign and verify the contents of an entire file.
  410. *;:Copyright © 1993, Apple Computer Inc. All Rights Reserved.(Ò??ˇ §◊#ˇ ˇˇˇˇ#◊ 
  411. d, Palatino
  412. .+Z.Digital Signature Demo(.˚11) .,     Helvetica
  413. °dONLNd/<>z(YZHeritage
  414. °dONLNd    =TKé+
  415. Superclass°dONLNd=∫K¯)f
  416. CSignature°dONLNdKTYç(tr
  417. Subclasses°dONLNd*K∫Y◊)fnone
  418. °dONLNd/_<n„(âZUsing CSignedDataFile
  419. °dONLNdEs<Å⁄*JUse this as part of your application’s Open and Close document processing.
  420. °dONLNdêá<ñz*Methods
  421. °dONLNdòõ<©–*GExcept as shown, all methods use the Failure mechanism (as described in°dONLNd‡©<∑∫*G<Exceptions.h> to report errors. In certain cases, this means that your°dONLNd(∑<≈∫*Aapplication must establish a TRY/CATCH context when calling these°dONLNdj≈<”p*methods.°dONLNdtŸ<Á*$Construction and destruction methods,
  422. Courier°dONLNdôÌT˘p+void°dONLNd°ÌÃ˘f)xISignedDataFile(void);°dONLNd∏ˇ<
  423. ÷((ZInitalize the object instance.°dONLNd◊Tp+void°dONLNdflà )x    SignFile(°dONLNdÍl+¿(Hä const FSSpec°dONLNd¯‰+8)x *signerFile,°dONLNd+l7‹(TäConstStr255Param°dONLNd+‰7?)x
  424. promptString,°dONLNd&7lC¿(`ä const FSSpec°dONLNd47‰C*)x
  425. *dataFile,°dONLNd@ClO‹(läSIGStatusProcPtr°dONLNdQC‰O*)x
  426. statusProc°dONLNd\OT[b(xr);°dONLNd_a<o·(äZRSign the file specified by dataFile. If signerFile is not NULL, it will be used to°dONLNd≤o<}⁄*Mdefine the signer file, while if NULL, the toolbox will prompt for the user’s°dONLNd}<ã—*Nsigner file. Prompt is used to prompt the user for a signer file, if "\p", the°dONLNdOã<ô”*Jdefault prompt will be used. SignPrepare returns the size of the Signature°dONLNdöô<ß›*Lrecord. StatusProc defines the user status procedure. Use gSIGStatusProc for°dONLNdÁß<µ¨*the default window.°dONLNd¸ª<…¿*HBecause of the way the Think Class Library closes files, you should call°dONLNdE…<◊ˇ*#SignFile in the following sequence:°dONLNdi·`Ôf+$1°dONLNdk·mÔÜ)
  427. 5Create a copy of the FSSpec associated with the file.°dONLNd°˘`f("~2°dONLNd£˘më)
  428. Write °dONLNd©˘ë»)$9all data and close the file. You can delete the CDataFile°dONLNd„m“(0ãobject at this time.°dONLNd¯`-f(H~3°dONLNd˙m-")
  429.  SignFile using the saved FSSpec.°dONLNd7`Ef(`~4°dONLNd7mE)
  430. Call DisposeSignerContext°dONLNd7K<YÎ(tZIYou should call SignPrepare…SignFile in a TRY/CATCH context, checking for°dONLNdÅY<gÆ*the following errors:°dONLNdóo<{¨*kSIGUserCanceled°dONLNd®m{∏(ñ2The user cancelled this signer°dONLNd«{â“*!request. You may choose to ignore°dONLNdÈâóK* this error.
  431. (ÒZ:Copyright © 1993, Apple Computer Inc. All Rights Reserved.(Ò??ˇΔ◊#ˇ ˇˇˇˇ#◊ 
  432. d, Palatino
  433. .+Z.Digital Signature Demo(.˚12) .,
  434. Courier°dONLNd1<=•(ZZkSIGPasswordErr°dONLNd/=∑(X2The user entered an incorrect°dONLNd.=KK*    password.°dONLNd9S<_∫(|ZkSIGSignerNotValid°dONLNdLQ_ß(z2The signer file is incorrect.°dONLNdkg<s{(êZ    wrPermErr°dONLNduesÀ(é2!The data file is marked read-only°dONLNdósÅ√* (perhaps it was already signed?)°dONLNdπáTìp(∞rvoid°dONLNd¡áÃì)x VerifyFile(°dONLNdŒìlü¿(ºä const FSSpec°dONLNd‹ì‰ü*)x
  435. *dataFile,°dONLNdËül´‹(»äSIGStatusProcPtr°dONLNd˘ü‰´*)x
  436. statusProc°dONLNd´T∑b(‘r);°dONLNdΩ<Àÿ(ÊZOVerify the signature in the file specified by dataFile.  StatusProc defines the°dONLNdWÀ<Ÿƒ*Euser status procedure. Use gSIGStatusProc for the default window. You°dONLNdùŸ<Á›*Ishould call VerifyFile in a TRY/CATCH context, checking for the following°dONLNdÁÁ<ı`*errors:°dONLNdÔ˝<    ¨*kSIGUserCanceled°dONLNd˚    ◊($2$The user cancelled this verification°dONLNd%    “*!request. You may choose to ignore°dONLNdG%K* this error.°dONLNdT-<9¡(VZkSIGVerifyFailedErr°dONLNdh+9µ(T2 Verification failed: the file or°dONLNdâ9G”* signature may have been changed.°dONLNd´O<[‰(xZkSIGInvalidCredentialErr°dONLNdƒM[æ(v2Verification succeeded, but the°dONLNd‰[i√*credentials are pending or have°dONLNdiwœ*%expired. The context is still active.°dONLNd+}TâÖ(¶rBoolean°dONLNd5}Ãâ')x
  437. FileIsSigned(°dONLNdDâlï¿(≤ä const FSSpec°dONLNdRâ‰ï*)x
  438. *dataFile,°dONLNd]ïT°b(ær);°dONLNd`ß<µ⁄(–ZMReturn TRUE if the specified file has a signature. Note that the signature is°dONLNdƵ<√Å*
  439. not verified.
  440. (ÒZ:Copyright © 1993, Apple Computer Inc. All Rights Reserved.(Ò??ˇ